package com.bjpowernode.controller;

import com.bjpowernode.entity.TClueRemark;
import com.bjpowernode.query.ClueRemarkQuery;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.ClueRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 线索备注控制器
 * 处理与线索备注相关的HTTP请求
 */
@RestController // Spring注解，标识这是一个RESTful风格的控制器
public class ClueRemarkController {
    // 注入线索备注服务
    @Resource
    private ClueRemarkService clueRemarkService;

    /**
     * 添加线索备注
     * @param clueRemarkQuery 线索备注查询对象，包含要添加的备注信息
     * @return 操作结果，成功返回OK，失败返回FAIL
     */
    @PostMapping("/api/clue/remark") // 处理POST请求，路径为/api/clue/remark
    public Result addRemark(@RequestBody ClueRemarkQuery clueRemarkQuery) {
        // 调用服务层方法保存线索备注
        int count = clueRemarkService.saveClueRemark(clueRemarkQuery);
        // 根据保存结果返回相应的操作结果
        return count > 0 ? Result.OK() : Result.FAIL();
    }

    /**
     * 根据线索ID分页获取线索备注列表
     * @param clueId 线索ID
     * @param current 当前页码
     * @return 分页后的线索备注列表
     */
    @GetMapping("/api/clue/{clueId}/remarks") // 处理GET请求，路径为/api/clue/{clueId}/remarks
    public Result getActivities(@PathVariable Integer clueId, Integer current) {
        // 调用服务层方法分页获取线索备注
        PageInfo<TClueRemark> pageInfo = clueRemarkService.getClueRemarkByPage(clueId, current);
        // 返回分页结果
        return Result.OK(pageInfo);
    }

    /**
     * 根据ID获取线索备注详情
     * @param id 线索备注ID
     * @return 线索备注详情
     */
    @GetMapping("/api/clue/remark/detail/{id}") // 处理GET请求，路径为/api/clue/remark/detail/{id}
    public Result getClueRemarkDetailById(@PathVariable Integer id) {
        // 调用服务层方法根据ID获取线索备注详情
        TClueRemark tClueRemark = clueRemarkService.getClueRemarkDetailById(id);
        // 返回线索备注详情
        return Result.OK(tClueRemark);
    }

    /**
     * 编辑线索备注
     * @param clueRemarkQuery 线索备注查询对象，包含要更新的备注信息
     * @return 操作结果，成功返回OK，失败返回FAIL
     */
    @PostMapping("/api/clue/remark/edit") // 处理POST请求，路径为/api/clue/remark/edit
    public Result updateClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery) {
        // 调用服务层方法更新线索备注
        int count = clueRemarkService.updateClueRemark(clueRemarkQuery);
        // 根据更新结果返回相应的操作结果
        return count > 0 ? Result.OK() : Result.FAIL();
    }

    /**
     * 根据ID删除线索备注
     * @param id 线索备注ID
     * @return 操作结果，成功返回OK，失败返回FAIL
     */
    @DeleteMapping("/api/clue/remark/delete/{id}") // 处理DELETE请求，路径为/api/clue/remark/delete/{id}
    public Result deleteClueRemarkById(@PathVariable Integer id) {
        // 调用服务层方法根据ID删除线索备注
        int count = clueRemarkService.deleteClueRemarkById(id);
        // 根据删除结果返回相应的操作结果
        return count == 1 ? Result.OK(count) : Result.FAIL();
    }
}
